package ldk.apps.adbconnections

import ldk.apps.adbconnections.beans.StringResult
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test

/**
 * MainServer的单元测试
 * Created by ldkxingzhe@163.com on 2018/2/5.
 */
class MainServerTest{

    private lateinit var server: MainServer

    @Before
    fun setUp(){
        server = MainServer()
        server.handleLog = {
            println(it)
        }
    }

    @After
    fun tearDown(){
        server.closeServer()
    }

    @Test
    fun echoHello(){
        println("GOOD")
    }

    @Test
    fun keepLive(){
        server.handleOnAction = {
            action: Int, content: ByteArray? ->
            val str = content?.toString(Charsets.UTF_8)
            println("action is $action, and content: $str")
            val response = StringResult()
            response.result = "消息已经接收， 你可以休息了"
            server.writeResponse(response)
        }

        Thread.sleep(30 * 1000)
    }
}